package com.blacktry.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blacktry.entity.model.ApiResult;
import com.blacktry.entity.model.JudgeQuestion;
import com.blacktry.entity.model.PaperManage;
import com.blacktry.entity.model.request.PaperRequest;
import com.blacktry.mapper.PaperManageMapper;
import com.blacktry.service.PaperManageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 试卷管理表 服务实现类
 * </p>
 *
 * @author blackTry
 * @since 2021-08-10
 */
@Service
public class PaperManageServiceImpl extends ServiceImpl<PaperManageMapper, PaperManage> implements PaperManageService {
    @Override
    public int insert(PaperManage paperManage) {
        return this.baseMapper.insert(paperManage);
    }

    @Override
    public List<Integer> findAllIds() {
        return this.baseMapper.findAllIds();
    }

    @Override
    public Page<PaperManage> findAllIdsPage(PaperRequest paperRequest, Page<PaperManage> paperManagePage) {
//        LambdaQueryWrapper<PaperManage> wrapper = new LambdaQueryWrapper<>();
       QueryWrapper<PaperManage> wrapper = new QueryWrapper<>();
        // 根据禁用条件查询
        wrapper.select("DISTINCT `paper_id`");
        return this.baseMapper.selectPage(paperManagePage,wrapper);
    }

    @Override
    public Integer delete(Integer paperId,Integer id,Integer questionType) {
        return this.baseMapper.deleteByPaperIdAndQuestionId(paperId,id,questionType);
    }

    @Override
    public Integer deleteBatchIds(Integer paperId,String[] ids,Integer questionType) {
        return this.baseMapper.deleteBatchIdsByPaperIdAndQuestionId(paperId,Arrays.asList(ids),questionType);
    }

    @Override
    public List<PaperManage> selectAll() {
        return this.baseMapper.selectList(null);
    }

}
